package com.youlu.campus.service.qq;

import com.youlu.campus.base.exception.BusinessException;
import com.youlu.campus.entity.QQConfigInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class QQConfigInfoService {

    @Autowired
    private MongoTemplate mongoTemplate;

    public QQConfigInfo findByAppId(String appId){
        if(StringUtils.isEmpty(appId)){
            log.info(":>>> qq应用:{} 配置不存在",appId);
            throw new BusinessException("配置不存在,请联系客服!");
        }
        log.info(" appId - > {}" ,appId);
        Query query = new Query();
        query.addCriteria(Criteria.where("appId").is(appId));
       return this.mongoTemplate.findOne(query,QQConfigInfo.class);
    }

}
